package com.mxpio.erp.equipment.service.impl;

import com.mxpio.erp.common.equipment.entity.EquipmentRepairAssistants;
import com.mxpio.erp.common.equipment.service.EquipmentRepairAssistantsService;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import com.mxpioframework.security.entity.User;
import com.mxpioframework.security.util.SecurityUtils;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class EquipmentRepairAssistantsServiceImpl extends BaseServiceImpl<EquipmentRepairAssistants> implements EquipmentRepairAssistantsService {



	@Override
	public List<EquipmentRepairAssistants> selectByMainId(String mainId) {
		Criteria c = Criteria.create().addCriterion("bizNo", Operator.EQ, mainId);
		return list(EquipmentRepairAssistants.class,c);
	}

	/**
	 * 查询当前用户有多少个协助工单的信息
	 * @return
	 */
	@Override
	@Transactional
	public List<EquipmentRepairAssistants> userAssistance() {
		//获取当前登录用户大的信息
		User sysUser = SecurityUtils.getLoginUser();
		String username = sysUser.getUsername();
		Criteria personNo = Criteria.create().addCriterion("personNo", Operator.EQ, username);
		//查询当前登录用户有多少个协助工单的信息
		List<EquipmentRepairAssistants> list = this.list(EquipmentRepairAssistants.class, personNo);
		if (list.size() > 0){
			return list;
		}
		return null;
	}


}
